package effective_java.design_pattern.builder;

import org.apache.commons.lang3.Validate;

/**
 * @author Try
 */
public class StudentBuilderImpl extends Student implements Student.Builder {

    private String id;
    private String name;
    private Integer age;
    private String address;

    public StudentBuilderImpl() {}

    public StudentBuilderImpl(StudentBuilderImpl studentBuilder) {
       this.id = studentBuilder.id;
       this.name = studentBuilder.name;
       this.age = studentBuilder.age;
       this.address = studentBuilder.address;
    }

    @Override
    public  Student.Builder id(String id) {
        this.id = id;
        return this;
    }

    @Override
    public  Student.Builder name(String name) {
        this.name = name;
        return this;
    }

    @Override
    public  Student.Builder age(Integer age) {
        this.age = age;
        return this;
    }

    @Override
    public  Student.Builder address(String address){
        this.address = address;
        return this;
    }

    @Override
    public Student build() {
        Validate.notNull(this.id,"ID不能为空");
        Validate.notNull(this.name,"姓名不能为空");
        return new StudentBuilderImpl(this);
    }
}
